import sys
import HarmonyOsBasicInfo
import HarmonyOsSignature
import HarmonyOsDependencies


def printHelp(command):
    if command == '-i':
        print("-i: 修改鸿蒙基本信息(不包含包名，应用图标)：workspace, versionCode, versionName, appNameCN, appNameUS ,bundleId")
        print( "HarmonyOs.py -i '{workspace}' '{versionCode}' '{versionName}' '{appNameCN}' '{appNameUS}' '{bundleId}'")
        exit(0)
    elif command == '-m':
        print("-m: 修改鸿蒙模块信息：workspace, name, version, author")
        print( "HarmonyOs.py -m '{workspace}' '{name}' '{version}'  '{versionName}'  '{author}'")
        exit(0)
    elif command == '-b':
        print("-b: 修改鸿蒙基本信息：workspace, bundleId, versionCode, versionName, appNameCN, appNameUS, appBackground, appForeground")
        print( "HarmonyOs.py -b '{workspace}' '{bundId}' '{versionCode}'  '{versionName}'  '{appNameCN}' '{appNameUS}' '{appBackground}' '{appForeground}'")
        exit(0)
    elif command == '-s':
        print("-s: 修改鸿蒙签名信息：workspace，signingConfig, signingName")
        print("HarmonyOs.py -s '{workspace}' '{signingConfig}' '{signingName}'")
        exit(0)
    elif command == '-a':
        print("-a: 模块依赖：workspace，dependencies")
        print("HarmonyOs.py -a '{workspace}' '{dependencies}'")
        exit(0)
    elif command == '-gmn':
        print("-gmn: 获取模块名称")
        print("HarmonyOs.py -gmn")
        exit(0)
    elif command == '-gmt':
        print("-gmt: 获取模块类型")
        print("HarmonyOs.py -gmt")
        exit(0)
    else:
        print("Use: HarmonyOs.py -[i|b|s|a|gmn]")

        print("-i: 修改鸿蒙基本信息(不包含包名，应用图标)：workspace, versionCode, versionName, appNameCN, appNameUS ,bundleId")
        print( "HarmonyOs.py -i '{workspace}' '{versionCode}' '{versionName}' '{appNameCN}' '{appNameUS}' '{bundleId}'")

        print( "-b: 修改鸿蒙基本信息：workspace, bundleId, versionCode, versionName, appNameCN, appNameUS, appBackground, appForeground")
        print( "HarmonyOs.py -b '{workspace}' '{bundId}' '{versionCode}'  '{versionName}'  '{appNameCN}' '{appNameUS}' '{appBackground}' '{appForeground}'")

        print("-m: 修改鸿蒙模块信息：workspace, moduleFileName, name, version, author")
        print("HarmonyOs.py -b '{workspace}' '{moduleFileName}' '{name}' '{version}'  '{versionName}'  '{author}'")

        print("-s: 修改鸿蒙签名信息：workspace，signingConfig, signingName")
        print("HarmonyOs.py -s '{workspace}' '{signingConfig}' '{signingName}'")

        print("-a: 模块依赖：workspace，dependencies")
        print("HarmonyOs.py -a '{workspace}' '{dependencies}'")

        print("-gmn: 获取模块名称：workspace, moduleFileName")
        print("HarmonyOs.py -gmn '{workspace}' '{moduleFileName}'")

        print("-gmt: 获取模块类型：workspace, moduleFileName")
        print("HarmonyOs.py -gmt '{workspace}' '{moduleFileName}'")

        exit(0)

TEST_DEFAULT_SIGNING = '{ "certpath": "./sign/debug.cer", "storePassword": "0000002285C66C06B99314938D9215DCD678B256604A871674F261F5E84481233FBA053B7AAC4C826F37E205F3163DBB8E71","keyAlias": "galaxy", "keyPassword": "000000223D1186566821BF31B1A34A4E335502906822F368AD7D5783CD8749ED7AC04C014CE0E0DBC8E8876D3148F9C280AE", "profile": "./sign/debug.p7b","signAlg": "SHA256withECDSA", "storeFile": "./sign/debug.p12"}'

TEST_PUBLIC_SIGNING = '{"storePassword": "00000024DDABF29F68B70F3444DB229B7C6FCFCE44008A11F02CC27E414C0413B292A3425CC7138C94400FA9B515618FA0873741", "certpath": "./sign/public.cer","keyAlias": "galaxy","keyPassword": "00000024DC2EF7BD11B45C69EBD529466B04817ADED389A7EB125296F14BA7219BDA5C95681776089368442D68C2DF2C64138436","profile": "./sign/publicRelease.p7b", "signAlg": "SHA256withECDSA", "storeFile": "./sign/release.p12"}'

TEST_DEPENDENCIES = '[{"name":"@amap/amap_lbs_location",version: "1.1.0"},{"name":"@ohos/lottie","version":"2.0.15"}, {"name":"@sweet/network-kit","version":"1.1.2"}]'

APP_BACK_GROUND = 'https://geely-admp-test-oss.oss-cn-hangzhou.aliyuncs.com/testIcon/new_app_background.png'
APP_FORE_GROUND = 'https://geely-admp-test-oss.oss-cn-hangzhou.aliyuncs.com/testIcon/new_app_foreground.png'


def test():
      # HarmonyOsBasicInfo.changeModuleBasicInfo('.', 'hoo_dialog','@geely/geely_dialog', '1.0.1', 'e-zhaihao')
      HarmonyOsBasicInfo.getModuleName('.', 'hoo_dialog')
      # HarmonyOsBasicInfo.changeBasicInfo('.', 'com.example.new', 100, '1.0.1', '修改后的名称', APP_BACK_GROUND, APP_FORE_GROUND)
      # HarmonyOsBasicInfo.changeAppNameVersionCodeVersionName('.', 100, '1.0.1', '修改后的名称', 'laster name')
      # HarmonyOsDependencies.addDependencies('.', TEST_DEPENDENCIES)
      # HarmonyOsSignature.changeSigningInfo('.', TEST_DEFAULT_SIGNING, 'default')
      # HarmonyOsSignature.changeSigningInfo('.', TEST_DEFAULT_SIGNING, 'debug')
      # HarmonyOsSignature.changeSigningInfo('/Users/gymd/DevEcoStudioProjects/hm-demo', TEST_PUBLIC_SIGNING, 'production')


if __name__ == "__main__":
    if len(sys.argv) < 2:
        printHelp('error')
    command = sys.argv[1]
    print(f"命令：{command}")
    print(f"长度：{len(sys.argv)} 参数：{sys.argv[0]}{sys.argv}")
    if command == "-b":
        if len(sys.argv) < 10:
            printHelp(command)
        HarmonyOsBasicInfo.changeBasicInfo(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6],sys.argv[7],sys.argv[8],sys.argv[9])
    elif command == "-i":
        if len(sys.argv) < 8:
            printHelp(command)
        HarmonyOsBasicInfo.changeAppNameVersionCodeVersionName(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5],sys.argv[6],sys.argv[7])
    elif command == "-m":
        if len(sys.argv) < 7:
            printHelp(command)
        HarmonyOsBasicInfo.changeModuleBasicInfo(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5],sys.argv[6])
    elif command == "-s":
        if len(sys.argv) < 5:
            printHelp(command)
        HarmonyOsSignature.changeSigningInfo(sys.argv[2], sys.argv[3], sys.argv[4])
    elif command == "-a":
        if len(sys.argv) < 4:
            printHelp(command)
        HarmonyOsDependencies.addDependencies(sys.argv[2], sys.argv[3])
    elif command == "-gmn":
        if len(sys.argv) < 4:
            printHelp(command)
        HarmonyOsBasicInfo.getModuleName(sys.argv[2], sys.argv[3])
    elif command == "-gmt":
        if len(sys.argv) < 4:
            printHelp(command)
        HarmonyOsBasicInfo.getModuleType(sys.argv[2], sys.argv[3])
    else:
        printHelp('error')

#使用用例

# 修改鸿蒙基本信息(不包含包名，应用图标)
# python HarmonyOs.py -i '/Users/gymd/DevEcoStudioProjects/hm-demo' '100' '1.0.1' '名称' 'laster name' 'com.example.new'
# python HarmonyOs.py -i '.' '100' '1.0.1' '名称' 'laster name' 'com.example.new'
# 修改鸿蒙基本信息
# python HarmonyOs.py -b '/Users/gymd/DevEcoStudioProjects/hm-demo' 'com.example.new' '100' '1.0.1' '名称' 'laster name' 'https://geely-admp-test-oss.oss-cn-hangzhou.aliyuncs.com/testIcon/w_app_background.png' 'https://geely-admp-test-oss.oss-cn-hangzhou.aliyuncs.com/testIcon/new_app_foreground.png'
# python HarmonyOs.py -b '.' 'com.example.new' '100' '1.0.1' '名称' 'laster name' 'https://geely-admp-test-oss.oss-cn-hangzhou.aliyuncs.com/testIcon/w_app_background.png' 'https://geely-admp-test-oss.oss-cn-hangzhou.aliyuncs.com/testIcon/new_app_foreground.png'

# 修改鸿蒙签名信息
# python HarmonyOs.py -s '/Users/gymd/DevEcoStudioProjects/hm-demo' '{"storePassword": "00000024DDABF29F68B70F3444DB229B7C6FCFCE44008A11F02CC27E414C0413B292A3425CC7138C94400FA9B515618FA0873741", "certpath": "./sign/public.cer","keyAlias": "galaxy","keyPassword": "00000024DC2EF7BD11B45C69EBD529466B04817ADED389A7EB125296F14BA7219BDA5C95681776089368442D68C2DF2C64138436","profile": "./sign/publicRelease.p7b", "signAlg": "SHA256withECDSA", "storeFile": "./sign/release.p12"}' 'production'
# python HarmonyOs.py -s '.' '{"storePassword": "00000024DDABF29F68B70F3444DB229B7C6FCFCE44008A11F02CC27E414C0413B292A3425CC7138C94400FA9B515618FA0873741", "certpath": "./sign/public.cer","keyAlias": "galaxy","keyPassword": "00000024DC2EF7BD11B45C69EBD529466B04817ADED389A7EB125296F14BA7219BDA5C95681776089368442D68C2DF2C64138436","profile": "./sign/publicRelease.p7b", "signAlg": "SHA256withECDSA", "storeFile": "./sign/release.p12"}' 'production'
#python HarmonyOs.py -s '.' '{"storeFile": "/Users/gymd/Downloads/打包机/证书/debug/agp_debug.p12", "storePassword": "00000018BBFC45A66A25918B0E8F982290BA232CB45516454714972D89275417E4BBB2E91DF2543F","keyAlias": "debug","keyPassword": "000000186B10CEEB66845C33BE1A9307362FEC529113B2626D0FCA6369BCDC76AC34C6A97703A826", "signAlg": "SHA256withECDSA","profile": "/Users/gymd/Downloads/打包机/证书/debug/agp_debug.p7b","certpath": "/Users/gymd/Downloads/打包机/证书/debug/agp_debug.cer"}' 'production'

# 模块依赖
# python HarmonyOs.py -a '/Users/gymd/DevEcoStudioProjects/hm-demo' '[{"name":"@amap/amap_lbs_location",version: "1.1.0"},{"name":"@ohos/lottie","version":"2.0.15"}, {"name":"@sweet/network-kit","version":"1.1.2"}]'
# python HarmonyOs.py -a '.' '[{"name":"@amap/amap_lbs_location",value: "1.1.0"},{"name":"@ohos/lottie","version":"2.0.15"}, {"name":"@sweet/network-kit","version":"1.1.2"}]'

# 模块版本修改
# python HarmonyOs.py -m '/Users/gymd/DevEcoStudioProjects/hm-demo' 'hoo_dialog' '@geely/geely_dialog' '1.0.1' 'e-zhaihao'
# python HarmonyOs.py -m '.' 'hoo_dialog' '@geely/geely_dialog' '1.0.1' 'e-zhaihao'

# 获取模块名称
# python HarmonyOs.py -gmn '/Users/gymd/DevEcoStudioProjects/hm-demo' 'hoo_dialog'
# python HarmonyOs.py -gmn '.' 'hoo_dialog'

# 获取模块类型
# python HarmonyOs.py -gmt '/Users/gymd/DevEcoStudioProjects/hm-demo' 'hoo_dialog'
# python HarmonyOs.py -gmt '.' 'hoo_dialog'